<?php

	class JieSuanXinXiController extends CommonController{

		public $model;

		public function __init(){

			parent::__init();
			$this->model = K('Shop_oder');
		}

		public function index(){
			if (!isset($_SESSION['uid']) && !isset($_SESSION['username'])) {

				go(U('Index/Login/index'));
			}

			$province = K('Hd_area')->where("parent_id=1")->all();
			foreach ($province as $k => $v) {
				$province[$k]['son'] = K('Hd_area')->where("parent_id={$v['area_id']}")->all();
			}
			$this->assign('province',$province);

			//接收结算的内容
			// p($_SESSION);
			$goodsData = $_SESSION['cart']['goods'];

			$this->assign('goodsData',$goodsData);

			$totalprice = $_SESSION['cart']['total'];

			$this->assign('totalprice',$totalprice);
			//彩条框中的地址信息
			$uid = (int)$_SESSION['uid'];
			$dizhiData = K('Shop_dizhi')->where("shop_user_uid={$uid}")->field('consignee,address,num')->all();
			// p($dizhiData);
			$this->assign('dizhiData',$dizhiData);

			$this->dis('jiesuanxinxi');

		}

		public function get_son(){

			$area_id = Q('post.id',0,'intval');
			$areaData = K('Hd_area')->where("parent_id={$area_id}")->all();

			$this->ajax($areaData);
		}

		public function place_add(){
			if (IS_POST) {
				$data = array(
					'number' =>Cart::getOrderId(),
					'time'     =>time(),
					'status'   =>'未发货',
					'shop_user_uid'=>$_SESSION['uid'],
					'total'        =>$_SESSION['cart']['total'],

					);
				$_SESSION['number'] = $data['number'];
				$this->model->add($data);

				$dizhiData = array(
					'consignee' => Q('post.consignee'),
					'address'   => Q('post.address'),
					'num'      =>Q('post.num'),
					'time'     =>time(),
					'shop_user_uid'=>$_SESSION['uid'],
					);
				$dizhiData['number'] = $_SESSION['number'];

				K('Shop_dizhi')->add($dizhiData);

				//获取地址表中的信息
				$uid = (int)$_SESSION['uid'];
				$dizhiData = K('Shop_dizhi')->where("shop_user_uid={$uid}")->field('consignee,address,num')->order('time asc')->limit(1)->all();
				// p($dizhiData);
				$this->ajax($dizhiData);

				
			}
		}

		public function get_place(){
			$shengData = Q('post.sheng',0,'intval');
			$tem['sheng'] = K('Hd_area')->where("area_id={$shengData}")->getField('area_name');
			$shiData = Q('post.shi',0,'intval');
			$tem['shi'] = K('Hd_area')->where("area_id={$shiData}")->getField('area_name');
			$quData = Q('post.qu',0,'intval');
			$tem['qu'] = K('Hd_area')->where("area_id={$quData}")->getField('area_name');

			$this->ajax($tem);

		}

		public function tuichu(){
			session(NULL);
			$this->success('退出成功',go(U("Index/Login/index")));

		}
		//删除shop_oder表中的信息
		public function del(){
			$did = Q('post.did',0,'intval');
			K('Shop_dizhi')->del($did);
			$this->success('删除成功');
		}
	}









?>